﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using ScrumTable.Common.Collections;
using ScrumTable.DL.Data.Common;
using ScrumTable.DL.Data.Generic.Test.Mocks;
using ScrumTable.DL.Data.Generic.Test.Mocks.Config.Driver;
using ScrumTable.DL.Data.Generic.Test.Mocks.Config.Schema;

#endregion

namespace ScrumTable.DL.Data.Generic.Test
{
    /// <summary>
    /// This is the test class for DataSchemaSelector class.
    /// </summary>
    [TestClass]
    public class DataSchemaSelectorTest
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private const string InternalSchemaName = "Internal Schema";
        private const string OverwrittenSchemaName = "Generic Schema";

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        #endregion

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new DataSchemaSelectorTest instance.
        /// </summary>
        public DataSchemaSelectorTest()
        {
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        [TestMethod]
        public void TestSelected()
        {
            IDataAssemblyInfo selectorStub = new DataContextInfoStub(
                TestContext.TestDir,
                dci => new GenericDataSchemaSelectorStub(dci),
                dci => new GenericDriverConfigSelectorStub(dci));
            Assert.IsNotNull(selectorStub.DataSchemaSelector.Selected);
            selectorStub.DataSchemaSelector.Selected = selectorStub.DataSchemaSelector.First();
            Assert.AreEqual(selectorStub.DataSchemaSelector.First(), selectorStub.DataSchemaSelector.Selected);
        }

        [TestMethod]
        public void TestCount()
        {
            IDataAssemblyInfo selectorStub = new DataContextInfoStub(
                TestContext.TestDir,
                dci => new GenericDataSchemaSelectorStub(dci),
                dci => new GenericDriverConfigSelectorStub(dci));
            Assert.IsTrue(selectorStub.DataSchemaSelector.Count() == 3);
        }

        [TestMethod]
        public void TestElements()
        {
            IDataAssemblyInfo selectorStub = new DataContextInfoStub(
                TestContext.TestDir,
                dci => new GenericDataSchemaSelectorStub(dci),
                dci => new GenericDriverConfigSelectorStub(dci));
            Assert.AreEqual(InternalSchemaName, selectorStub.DataSchemaSelector.First().Name);
            Assert.AreEqual("Test Schema2 With No Content", selectorStub.DataSchemaSelector.Second().Name);
            Assert.AreEqual("Local XML data storage (for UnitTests)", selectorStub.DataSchemaSelector.Third().Name);
        }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}
